---
import { getAllBestPracticeTopicFiles } from '../../../lib/best-practice-topic';
import type { BestPracticeTopicFileType } from '../../../lib/best-practice-topic';

export const prerender = true;

export async function getStaticPaths() {
  const topicPathMapping = await getAllBestPracticeTopicFiles();

  return Object.keys(topicPathMapping).map((topicSlug) => {
    const topicDetails = topicPathMapping[topicSlug];
    const bestPracticeId = topicDetails.bestPracticeId;
    const topicId = topicSlug.replace(`/${bestPracticeId}/`, '');

    return {
      params: {
        topicId,
        bestPracticeId,
      },
      props: topicDetails,
    };
  });
}

const { file } = Astro.props as BestPracticeTopicFileType;

const fileWithoutBasePath = file.file?.replace(/.+?\/src\/data/, '/src/data');
const gitHubUrl = `https://github.com/kamranahmedse/developer-roadmap/tree/master${fileWithoutBasePath}`;
---

<div data-github-url={gitHubUrl}></div>

<file.Content />
